package com.duobeiyun.gmstest.work.sample

import android.content.Context
import android.util.Log
import androidx.work.Data
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.duobeiyun.gmstest.TestInstance

/**
 * 同步测试用例
 */
open abstract class WorkSyncMode(appContext: Context, workerParams: WorkerParameters):
        Worker(appContext, workerParams) {
    private  val TAG = "WorkSyncMode"
    var number = "enter case number"
    override fun doWork(): Result {
        setNumber()
        Log.d("WorkSyncMode", "ListenableWorker ")
        val chooseAll = inputData.getBoolean("chose_all", false)
        var chooseNumber: Array<String>? = null
        if (!chooseAll){
            chooseNumber = inputData.getStringArray("chose_number")!!
            Log.d(TAG, " ListenableWorker: ${chooseNumber.contentToString()}")
        }
        if (!chooseAll && !chooseNumber?.contains(number)!!) {
            return Result.success()
        }
        try {
            realWork()
        }catch (throwable:Throwable){
            Log.e(TAG, " throwable: $throwable")
        }
        return Result.success()
    }

    abstract fun setNumber()
    open  fun realWork() {

    }

}